/********************************************************************************
 * Copyright (c)2016-2020, ShenZhen WanJiaAn Technology CO.,LTD.
 * All Rights Reserved.
 *
 * File Name     : DevAdc.c
 * Author        : joki.zhu
 * Date          : 2019-10-23
 *
 * Record        :
 * 1.Date        : 2019-10-23
 *   Author      : joki.zhu
 *   Modification: Created file
 ********************************************************************************/
#include "DevAdc.h"
#include "app_common.h"
#include "hi_hal_adc_inner.h"

#define ADC_CHANNEL     (1)

int AdcInit(void)
{
    int ret = 0;

    ret = HAL_ADC_Init(ADC_CHANNEL);
    if (ret < 0) {
        LOGE("HAL_ADC_Init chn%d failed\n", ADC_CHANNEL);
        return -1;
    }
    
    return 0;
}

int AdcGetVal(int adcChn, int *pAdcValue)
{
    if (pAdcValue == NULL) {
        LOGE("pAdcValue is NULL\n");
        return -1;
    }

    int ret = 0;
    ret = HAL_ADC_GetVal(adcChn, pAdcValue);
    if (ret < 0) {
        LOGE("HAL_ADC_GetVal chn%d failed\n", adcChn);
        return -1;
    }
    
    return 0;
}

// 提供给驱动校准前几帧图像效果
int get_adc(int chn)
{
    int ret = 0;
    int adcValue = 0;

    ret = AdcGetVal(ADC_CHANNEL, &adcValue);
    if (ret < 0) {
        LOGE("AdcGetVal chn%d failed\n", ADC_CHANNEL);
        return -1;
    }

    return adcValue;
}

int AdcDeinit(void)
{
    int ret = 0;

    ret = HAL_ADC_Deinit(ADC_CHANNEL);
    if (ret < 0) {
        LOGE("HAL_ADC_Deinit chn%d failed\n", ADC_CHANNEL);
        return -1;
    }
    
    return 0; 
}

